package com.example.demo;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;

public class elasticsearch {

    private RestHighLevelClient  client;

    @BeforeEach
    void setUp() {
        this.client = new RestHighLevelClient(RestClient.builder(
                HttpHost.create("http://192.168.91.128:9200")
        ));
    }

    @Test
    public void tes() throws IOException {
        // 创建发送请求的requesy对象 指定索引
       // CreateIndexRequest requesy = new CreateIndexRequest("hotel");
        // 构建DSL语句
      //  requesy.source(HotelConstants.MAPPING_TEMPLATE, XContentType.JSON);
        // 发送请求
       // client.indices().create(requesy, RequestOptions.DEFAULT);

        GetIndexRequest requesy = new GetIndexRequest("hotel");

        boolean exists = client.indices().exists(requesy, RequestOptions.DEFAULT);

        System.out.println(exists);
    }



    @AfterEach
    void tearDown() throws IOException {
        client.close();
    }

}
